package a11_单调栈;

import java.util.Stack;

/**
 * <p>
 * a01_每日温度复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/3/11
 */
public class a01_每日温度复习2 {
    public int[] dailyTemperatures(int[] temperatures) {
        int[] result = new int[temperatures.length];

        Stack<Integer> stack = new Stack<>();
        stack.push(0);

        for (int i = 1; i < temperatures.length; i++) {
            while (!stack.isEmpty() && temperatures[stack.peek()] < temperatures[i]){
                Integer pop = stack.pop();
                result[pop] = i - pop;
            }
            stack.push(i);
        }

        return result;

    }
}
